﻿using Prism.Commands;
using Prism.Common;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using WheelClean2.Model;
using WheelClean2.Mould;

namespace WheelClean.ViewModels
{
    class IOListViewModel : BindableBase, INavigationAware
    {
        private readonly IDialogService _dialog;
        private ObservableCollection<PLCInfos> _Infos;
        /// <summary>
        /// 设备列表
        /// </summary>
        public ObservableCollection<PLCInfos> Infos
        {
            get { return _Infos; }
            set { SetProperty(ref _Infos, value); }
        }

        public DelegateCommand<string> DelegateCommand_Open { get; private set; }

        IOListViewModel(IDialogService dialog)
        {
            _dialog = dialog;
            DelegateCommand_Open = new DelegateCommand<string>(Open);
            Infos = new ObservableCollection<PLCInfos>();
            Infos.AddRange(ModbusTCP.PLCInfosl);

           //Thread thread=new Thread (() =>
           // {
           //     while (true)
           //     {
           //         for (int i = 0; i < Infos.Count; i++)
           //         {
           //             Application.Current.Dispatcher.Invoke(() =>
           //             {

           //                 Infos[i].AddressSort += 1;
           //             });
           //         }
           //         Thread.Sleep(1000);
           //     }
             

           // });
           // thread.Start();








        }

        private void Open(string obj)
        {

            // viewName 可能是 "HomeView", "SettingsView", "AboutView" 等
          
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
          
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
           
        }
    }
}
